package com.demo.dao;

import com.demo.pojo.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName PermissionRepository
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/16 20:05
 * @Version 1.0
 **/
public interface PermissionRepository extends JpaRepository<Permission,Integer> {
    //根据登陆的用户名查询其所拥有的权限
    @Query(value = "select  p.permission_name from user u,permission p,role r,role_permission rp, user_role ur WHERE\n" +
            "u.id=ur.uid AND\n" +
            "ur.rid=r.id AND\n" +
            "r.id=rp.rid AND\n" +
            "rp.pid=p.id AND\n" +
            "u.name=?1",nativeQuery = true)
    List<String> findPermissionsByName(String name);

}
